package cn.hls.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import cn.hls.dao.ShipOrderSiteDao;
import cn.hls.entity.ShipOrderSite;
import cn.hls.exception.BussinessException;
import cn.hlsconstant.DataAssessEnum;

 
 
/**
  *@fileName: ShipOrderSiteDaoImpl.java
  *@package: cn.hls.dao.impl
　*@Description:货物数据操作接口实现类
　*@author: uuhui@163.com
  *@date: 2016年6月9日
 *
 */
@Component("shipOrderSiteDao")
public class ShipOrderSiteDaoImpl extends BaseDaoImpl<ShipOrderSite> implements ShipOrderSiteDao {
	@Override
	public List<ShipOrderSite> loadShipOrderSiteList(ShipOrderSite entity)throws Exception{
		// 定义查询Hql语句
		StringBuilder selectHql=new StringBuilder("from ShipOrderSite p inner join fetch p.site s  where p.deleted=? ");
		List<Object> paramList = new ArrayList<Object>();
		paramList.add(false);
		if (entity != null) {
			//按运单编号查询
			 if(entity.getShipOrderId()!=null){
				 selectHql.append("and p.shipOrderId=? ");
				 paramList.add(entity.getShipOrderId());
			 }
			 //按货物编号查询
			 if(entity.getSite()!=null ){
				 if(entity.getSite().getId()!=null){
					 selectHql.append("and g.id=? ");
					 paramList.add(entity.getSite().getId());
				 }
			 }
			 if(entity.getSiteType()!=null){
				 selectHql.append("and s.type=? ");
				 paramList.add(entity.getSiteType());
			 }
			 
		}
		return findByHql(selectHql.toString(), paramList.toArray());
	}

	@Override
	public void delete(Object shipOrderId) throws Exception {
		String hql="delete from ShipOrderSite where shipOrderId=?";
		 
		 try {
			executeHQLUpdate(hql.toString(),new Object[]{shipOrderId});
		} catch (Exception e) {
			e.printStackTrace();
			throw new BussinessException(DataAssessEnum.DELETE_ERROR,"删除货物信息失败" );
		}
	}

}
